package com.tuo.service.impl;

import com.tuo.beans.Detail;
import com.tuo.beans.Stopped;
import com.tuo.service.DetailService;
import com.tuo.service.StoppedService;
import com.tuo.util.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by tuo on 2016/1/9.
 */
@Service
public class DetailServiceImpl extends BaseServiceImpl<Detail> implements DetailService {
    @Autowired
    StoppedService stoppedService;

    @Override
    public void save(Detail detail) {
        try {
            super.save(detail);
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        if (detail.getStoppeds() == null || detail.getStoppeds().size() == 0) {
            return;
        }
        for (Stopped stopped : detail.getStoppeds()) {
            stopped.setDetailId(detail.getId());
            try {
                this.stoppedService.save(stopped);
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }
    }
}
